<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'供应商详情'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-if="leftInfo.AfterMarketState > 10" v-scrollHeight = "137"  v-loading="loading">
        <div class="analyItem anItemBor"  v-for="(item, index) in datalist" :key="index" @click="clickShow(1,item.shopName,item.shopId)">
            <p class="analyItemTit tx-center ">{{item.shopName}}</p>
            <div class="analyItemCon flexMar">
                <div class="flexMar col-md-12">
                    <div>
                        <img :src="item.shopPhoto" style="width:60px;height:60px;" alt="">
                    </div>
                    <div class="col-md-9 ml10">
                        <p class="col-md-6"><span class="cLightGray pr8">编号</span><span>{{item.shopCode}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">主营</span><span :title="item.manageMainType">{{item.manageMainType | truncate(10)}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">产品</span><span>{{item.matCount}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">商家</span><span>{{item.userCount}}</span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
        <div class="layerRtb-scroll thinScroll" v-else v-scrollHeight = "137" v-loading="loading">
        <div class="analyItem"  v-for="(item, index) in datalist" :key="index">
            <p class="analyItemTit tx-center">{{item.shopName}}</p>
            <div class="analyItemCon">
                <div class="flexMar col-md-12">
                    <div>
                        <img :src="item.shopPhoto" style="width:60px;height:60px;" alt="">
                    </div>
                    <div class="col-md-9 ml10">
                        <p class="col-md-6"><span class="cLightGray pr8">编号</span><span>{{item.shopCode}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">主营</span><span :title="item.manageMainType">{{item.manageMainType | truncate(10)}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">产品</span><span>{{item.matCount}}</span></p>
                        <p class="col-md-6"><span class="cLightGray pr8">商家</span><span>{{item.userCount}}</span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <p class="col-md-3"><span class="cLightGray pr8">产品</span><span>{{matCount}}</span></p>
                <p class="col-md-3"><span class="cLightGray pr8">店铺</span><span>{{datalist.length}}</span></p>
                <p class="col-md-3"><span class="cLightGray pr8">商家</span><span>{{shopCount}}</span></p>
            </div>
        </div>
    </div>
    <!-- 四段渲染容器 -->
    <transition-group class="animated faster" enter-active-class="animated faster slideInRight" leave-active-class="animated faster slideOutRight">
        <shop-detail v-if="fourIndex === 1" :key="1" :shopId="shopId" :name="shopName"></shop-detail>
    </transition-group>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { GetMatDetails, GetShopItemsByRwdID } from '../../Resources/Api/index'
import shopDetail from './four/shopDetail'
export default {
    components: {
        shopDetail
    },
    data () {
        return {
            loading: false, // 加载动画
            datalist: [], // 材料店铺数据
            fourIndex: -1, // 当前的index
            shopName: '', // 店铺名称
            shopId: '' // 店铺ID
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo']),
        shopCount () {
            // if (this.leftInfo.AfterMarketState > 10) {
            if (this.datalist.length > 0) {
                return this.datalist.map(startReady => startReady.userCount).reduce((acc, cur) => (parseFloat(cur) + acc), 0)
            } else {
                return 0
            }
            // } else {
            //     if (this.datalist.length > 0) {
            //         return this.datalist.map(startReady => startReady.userCount).reduce((acc, cur) => (parseFloat(cur) + acc), 0)
            //     } else {
            //         return 0
            //     }
            // }
        },
        matCount () {
            // if (this.leftInfo.AfterMarketState > 10) {
            if (this.datalist.length > 0) {
                return this.datalist.map(startReady => startReady.matCount).reduce((acc, cur) => (parseFloat(cur) + acc), 0)
            } else {
                return 0
            }
            // } else {
            //     if (this.datalist.length > 0) {
            //         return this.datalist.map(startReady => startReady.matCount).reduce((acc, cur) => (parseFloat(cur) + acc), 0)
            //     } else {
            //         return 0
            //     }
            // }
        }
    },
    created () {
        this.load()
    },
    methods: {
        // 点击出现四段
        clickShow (index, shopName, shopId) {
            this.fourIndex = index
            this.shopName = shopName
            this.shopId = shopId
        },
        // 加载材料店铺数据
        load () {
            let _this = this
            _this.loading = true
            if (this.leftInfo.AfterMarketState > 10) {
                GetShopItemsByRwdID({
                    rwdID: this.leftInfo.orderno
                }).then((result) => {
                    _this.datalist = result.data.body.items
                    _this.loading = false
                }).catch((err) => {
                    console.log(err)
                })
            } else {
                GetMatDetails({
                    F_OrderNo: this.leftInfo.orderno,
                    F_CityID: this.leftInfo.areaid
                }).then((result) => {
                    _this.datalist = result.data.Body
                    _this.loading = false
                }).catch((err) => {
                    console.log(err)
                })
            }
        },
        // 四段消失
        clickFourShow () {
            this.fourIndex = undefined
        }
    }
}
</script>
<style lang="scss" scoped>
    .flexMar {
        display:flex;
        justify-content: flex-start;
    }
</style>
